﻿using System;
using System.Collections.Generic;
using System.Text;
using VIP.Events;

namespace VIP.Domain.Core.DomainObject
{
    /// <summary>
    /// 聚合根
    /// </summary>
    public abstract class AggregateRoot
    {
        /// <summary>
        /// todo 通过属性注入优化掉
        /// </summary>
        //private readonly IEventSender _eventSender;
        //public AggregateRoot(IEventSender eventSender)
        //{
        //    _eventSender = eventSender;
        //}
        /// <summary>
        /// 事件发送者（属性注入）
        /// </summary>
        //public IEventSender EventsSender { get; }
        public abstract Guid Id { get; }
        public IList<IVIPEvent> Events { get; private set; }
        /// <summary>
        /// 新增事件
        /// </summary>
        /// <param name="@event"></param>
        public void AddEvent(IVIPEvent @event)
        {
            if (this.Events == null)
            {
                this.Events = new List<IVIPEvent>();
            }
            this.Events.Add(@event);
        }
        ///// <summary>
        ///// 执行聚合根所有事件
        ///// </summary>
        //public void ApplyEvent()
        //{
        //    foreach (var @event in Events)
        //    {
        //        _eventSender.SendAsync(@event);
        //    }
        //}
    }
}
